#include <vector>
#include "UserMachine.h"
#include "../Action.h"

// 初始化, 事件绑定动作, 状态保定事件
void UserMachine::Init()
{
    m_stateEventsMap.clear();
    
    std::vector<std::shared_ptr<State>> states; states.clear();

    std::shared_ptr<State> idleState = std::make_shared<UserState>(Idle);
    std::shared_ptr<State> inGameHallState = std::make_shared<UserState>(InGameHall);
    std::shared_ptr<State> inRoom201State = std::make_shared<UserState>(InRoom201);
    std::shared_ptr<State> inRoom202State = std::make_shared<UserState>(InRoom202);

    states.push_back(idleState);
    states.push_back(inGameHallState);
    states.push_back(inRoom201State);
    states.push_back(inRoom202State);

    for(int i = 0; i < states.size(); i++)
    {
        EventAction eventActionMap; eventActionMap.clear();
        m_stateEventsMap.insert(std::make_pair(states[i]->m_stateId, eventActionMap));
    }
    
    // 空闲 -----按下进入游戏按钮-------> 游戏大厅
    std::shared_ptr<Action> idle_InGameHall_Action = std::make_shared<EnterGameAction>(Idle, InGameHall);
    m_stateEventsMap[idleState->m_stateId].insert(std::make_pair(PressEnterGameBtn, idle_InGameHall_Action));
    
    // 游戏大厅 -----按下退出游戏按钮-------> 休闲
    std::shared_ptr<Action> inGamehall_Idle_Action = std::make_shared<LeaveGameAction>(InGameHall, Idle);
    m_stateEventsMap[inGameHallState->m_stateId].insert(std::make_pair(PressLeaveGameBtn, inGamehall_Idle_Action));
    
    // 游戏大厅 -----按下进入201游戏按钮-------> 在房间201
    std::shared_ptr<Action> inGamehall_InRoom201_Action = std::make_shared<EnterGameRoom201Action>(InGameHall, InRoom201);
    m_stateEventsMap[inGameHallState->m_stateId].insert(std::make_pair(PressEnterGameRoom201Btn, inGamehall_InRoom201_Action));

    // 在房间201 -----按下退出201游戏按钮-------> 游戏大厅
    std::shared_ptr<Action> inRoom201_InGamehall_Action = std::make_shared<LeaveGameRoom201Action>(InRoom201, InGameHall);
    m_stateEventsMap[inRoom201State->m_stateId].insert(std::make_pair(PressLeaveGameRoom201Btn, inRoom201_InGamehall_Action));

     // 游戏大厅 -----按下进入202游戏按钮-------> 在房间202
    std::shared_ptr<Action> inGamehall_InRoom202_Action = std::make_shared<EnterGameRoom202Action>(InGameHall, InRoom202);
    m_stateEventsMap[inGameHallState->m_stateId].insert(std::make_pair(PressEnterGameRoom202Btn, inGamehall_InRoom202_Action));

    // 在房间202 -----按下退出202游戏按钮-------> 游戏大厅
    std::shared_ptr<Action> inRoom202_InGamehall_Action = std::make_shared<LeaveGameRoom202Action>(InRoom202, InGameHall);
    m_stateEventsMap[inRoom202State->m_stateId].insert(std::make_pair(PressLeaveGameRoom202Btn, inRoom202_InGamehall_Action));
}